<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>实时评估测试 - n8n工作流监控系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', '微软雅黑', 'PingFang SC', 'Hiragino Sans GB', 'Heiti SC', 'WenQuanYi Micro Hei', 'Noto Sans CJK SC', 'Source Han Sans CN', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .header {
            text-align: center;
            color: white;
            margin-bottom: 30px;
        }
        
        .header h1 {
            font-size: 2.5em;
            margin-bottom: 10px;
        }
        
        .back-btn {
            background: white;
            color: #667eea;
            border: none;
            padding: 12px 30px;
            border-radius: 25px;
            font-size: 1em;
            font-weight: bold;
            cursor: pointer;
            margin-top: 15px;
            transition: all 0.3s;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            text-decoration: none;
            display: inline-block;
        }
        
        .back-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0,0,0,0.3);
        }
        
        .main-content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 30px;
        }
        
        .section {
            background: white;
            border-radius: 15px;
            padding: 30px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        }
        
        .section h2 {
            color: #333;
            margin-bottom: 20px;
            font-size: 1.5em;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
        }
        
        .form-group input,
        .form-group textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1em;
            font-family: inherit;
        }
        
        .form-group textarea {
            height: 120px;
            resize: vertical;
        }
        
        .btn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            padding: 12px 24px;
            border-radius: 8px;
            font-size: 1em;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            width: 100%;
        }
        
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        }
        
        .btn:disabled {
            background: #ccc;
            cursor: not-allowed;
            transform: none;
        }
        
        .result-section {
            background: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .result-item {
            margin-bottom: 15px;
            padding: 15px;
            background: white;
            border-radius: 8px;
            border-left: 4px solid #667eea;
        }
        
        .result-item.success {
            border-left-color: #10b981;
        }
        
        .result-item.error {
            border-left-color: #ef4444;
        }
        
        .result-item.warning {
            border-left-color: #f59e0b;
        }
        
        .result-label {
            font-weight: bold;
            color: #333;
            margin-bottom: 5px;
        }
        
        .result-value {
            color: #666;
            word-break: break-all;
        }
        
        .loading {
            text-align: center;
            color: #666;
            padding: 20px;
        }
        
        .error-message {
            background: #fee2e2;
            color: #991b1b;
            padding: 15px;
            border-radius: 8px;
            margin-top: 15px;
        }
        
        .success-message {
            background: #d1fae5;
            color: #065f46;
            padding: 15px;
            border-radius: 8px;
            margin-top: 15px;
        }
        
        .api-status {
            display: flex;
            align-items: center;
            gap: 10px;
            margin-bottom: 20px;
            padding: 10px;
            border-radius: 8px;
            background: #f0f9ff;
        }
        
        .status-indicator {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #ccc;
        }
        
        .status-indicator.online {
            background: #10b981;
        }
        
        .status-indicator.offline {
            background: #ef4444;
        }
        
        .test-messages {
            margin-top: 20px;
        }
        
        .test-message {
            background: #f8f9fa;
            border: 1px solid #e9ecef;
            border-radius: 8px;
            padding: 10px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .test-message:hover {
            background: #e9ecef;
            border-color: #667eea;
        }
        
        .test-message.selected {
            background: #e3f2fd;
            border-color: #667eea;
        }
        
        .progress-bar {
            width: 100%;
            height: 20px;
            background: #e9ecef;
            border-radius: 10px;
            overflow: hidden;
            margin-bottom: 10px;
        }
        
        .progress-fill {
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            width: 0%;
            transition: width 0.3s ease;
        }
        
        .progress-text {
            text-align: center;
            color: #666;
            font-size: 0.9em;
        }
        
        .evaluation-stats {
            margin-top: 20px;
        }
        
        .evaluation-stats h3 {
            color: #333;
            margin-bottom: 15px;
            font-size: 1.2em;
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 15px;
        }
        
        .stat-item {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 8px;
            text-align: center;
        }
        
        .stat-label {
            font-size: 0.9em;
            color: #666;
            margin-bottom: 5px;
        }
        
        .stat-value {
            font-size: 1.5em;
            font-weight: bold;
            color: #667eea;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🤖 实时评估测试</h1>
            <p>测试AI薪资信息评估功能</p>
            <a href="index.html" class="back-btn">← 返回主页</a>
        </div>
        
        <div class="main-content">
            <!-- 左侧：控制区域 -->
            <div class="section">
                <h2>薪资信息评估</h2>
                
                <!-- 评估按钮 -->
                <button class="btn" id="evaluateBtn" onclick="evaluateAllMessages()">开始评估所有消息</button>
                
                <!-- 评估进度 -->
                <div id="progressSection" style="display: none;">
                    <div class="progress-bar">
                        <div class="progress-fill" id="progressFill"></div>
                    </div>
                    <div class="progress-text" id="progressText">准备中...</div>
                </div>
                
                <!-- 评估统计 -->
                <div class="evaluation-stats" id="evaluationStats" style="display: none;">
                    <h3>评估统计</h3>
                    <div class="stats-grid">
                        <div class="stat-item">
                            <div class="stat-label">总消息数</div>
                            <div class="stat-value" id="totalMessages">0</div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-label">薪资相关</div>
                            <div class="stat-value" id="salaryMessages">0</div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-label">非薪资相关</div>
                            <div class="stat-value" id="nonSalaryMessages">0</div>
                        </div>
                        <div class="stat-item">
                            <div class="stat-label">过滤消息</div>
                            <div class="stat-value" id="filteredMessages">0</div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 右侧：结果显示 -->
            <div class="section">
                <h2>评估结果</h2>
                <div id="resultContainer">
                    <div class="loading">等待评估...</div>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        let isEvaluating = false;
        
        // 页面加载完成后执行
        document.addEventListener('DOMContentLoaded', function() {
            // 页面加载完成，显示等待状态
            document.getElementById('resultContainer').innerHTML = '<div class="loading">点击"开始评估所有消息"按钮开始评估</div>';
        });
        
        // 评估所有消息
        async function evaluateAllMessages() {
            if (isEvaluating) {
                return;
            }
            
            isEvaluating = true;
            document.getElementById('evaluateBtn').disabled = true;
            document.getElementById('evaluateBtn').textContent = '评估中...';
            
            // 显示进度条
            document.getElementById('progressSection').style.display = 'block';
            document.getElementById('evaluationStats').style.display = 'none';
            
            try {
                // 调用薪资分析API
                const response = await fetch('static/monitor_report.json');
                if (!response.ok) {
                    throw new Error('无法加载监控报告');
                }
                
                const reportData = await response.json();
                
                // 更新进度
                updateProgress(50, '正在分析数据...');
                
                // 模拟评估过程
                await new Promise(resolve => setTimeout(resolve, 1000));
                
                // 显示结果
                displayEvaluationResults(reportData);
                
                // 更新进度
                updateProgress(100, '评估完成');
                
            } catch (error) {
                showError(`评估失败: ${error.message}`);
            } finally {
                isEvaluating = false;
                document.getElementById('evaluateBtn').disabled = false;
                document.getElementById('evaluateBtn').textContent = '开始评估所有消息';
            }
        }
        
        // 更新进度
        function updateProgress(percent, text) {
            document.getElementById('progressFill').style.width = percent + '%';
            document.getElementById('progressText').textContent = text;
        }
        
        // 显示评估结果
        function displayEvaluationResults(reportData) {
            const container = document.getElementById('resultContainer');
            
            if (!reportData.ai_salary_analysis) {
                container.innerHTML = '<div class="error-message">未找到AI分析数据，请先运行monitor.py生成报告</div>';
                return;
            }
            
            const analysis = reportData.ai_salary_analysis;
            
            // 更新统计信息
            document.getElementById('totalMessages').textContent = analysis.total_messages || 0;
            document.getElementById('salaryMessages').textContent = analysis.total_salary_messages || 0;
            document.getElementById('nonSalaryMessages').textContent = analysis.total_non_salary_messages || 0;
            document.getElementById('filteredMessages').textContent = (analysis.total_messages || 0) - (analysis.total_salary_messages || 0) - (analysis.total_non_salary_messages || 0);
            
            // 显示统计信息
            document.getElementById('evaluationStats').style.display = 'block';
            
            // 显示详细结果
            container.innerHTML = `
                <div class="result-section">
                    <div class="result-item success">
                        <div class="result-label">评估完成</div>
                        <div class="result-value">已成功评估所有消息</div>
                    </div>
                    
                    <div class="result-item">
                        <div class="result-label">总候选人数</div>
                        <div class="result-value">${analysis.total_candidates || 0}</div>
                    </div>
                    
                    <div class="result-item warning">
                        <div class="result-label">薪资相关消息</div>
                        <div class="result-value">${analysis.total_salary_messages || 0}</div>
                    </div>
                    
                    <div class="result-item success">
                        <div class="result-label">非薪资相关消息</div>
                        <div class="result-value">${analysis.total_non_salary_messages || 0}</div>
                    </div>
                    
                    <div class="result-item">
                        <div class="result-label">薪资相关率</div>
                        <div class="result-value">${(analysis.overall_salary_rate || 0).toFixed(2)}%</div>
                    </div>
                </div>
            `;
        }
        
        // 显示错误
        function showError(message) {
            const container = document.getElementById('resultContainer');
            container.innerHTML = `
                <div class="error-message">
                    <strong>错误</strong><br>
                    ${message}
                </div>
            `;
        }
    </script>
</body>
</html>

